﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace groupAnalyzer.model
{
    public class Node : AbstractElementLdap
    {
        private List<NodeConnection> connections;
        private List<User> users;

        private string description, email, groupScope, groupType, notes;

        public string Description
        {
            get
            {
                return this.description;
            }
        }

        public string Email
        {
            get
            {
                return this.email;
            }
        }

        public string GroupScope
        {
            get
            {
                return this.groupScope;
            }
        }

        public string GroupType
        {
            get
            {
                return this.groupType;
            }
        }

        public string Notes
        {
            get
            {
                return this.notes;
            }
        }

        public List<User> Members
        {
            get
            {
                return this.users;
            }
        }

        public List<NodeConnection> Connections
        {
            get
            {
                return this.connections;
            }
        }

        public List<Node> Childs
        {
            get
            {
                List<Node> childNodes = new List<Node>();
                foreach (NodeConnection nodeConnection in this.connections)
                {
                    childNodes.Add(nodeConnection.To);
                }
                return childNodes;
            }
        }

        public List<User> Users
        {
            get
            {
                return this.users;
            }
        }

        public void addChild(Node node)
        {
            this.addChild(node, NodeConnectionMode.normal);
        }

        public void addChild(Node node, NodeConnectionMode mode)
        {
            this.connections.Add(new NodeConnection(this,node,mode));
        }

        public void addUser(User user)
        {
            this.users.Add(user);
        }

        public Node(string name,string fqdn, string description,string email,string groupScope, string groupType, string notes) : base(fqdn,name)
        {
            this.description = description;
            this.email = email;
            this.groupScope = groupScope;
            this.groupType = groupType;
            this.notes = notes;
            
            this.connections = new List<NodeConnection>();
            this.users = new List<User>();
        }
    }
}
